package com.student_system.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.student_system.system.entity.SysUser;
import com.student_system.system.mapper.SysUserMapper;
import com.student_system.system.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ljy
 * @since 2025-05-14
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Override
    public SysUser findByName(String username){
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", username);
        return this.getOne(queryWrapper);
    }

    @Override
    public Page<SysUser> queryUserPage(Page<SysUser> page, String userName){
        //构造查询条件（创建一个查询条件的实例）
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();

        //如果roleName(查询调剂)为空，则不添加查询条件；如果不为空，则添加查询条件
        if(StringUtils.isNotBlank(userName)){
            queryWrapper.like(SysUser::getUserName, userName);

            //queryWrapper.like("role_name","roleName")
        }
        //调用mybatis-plus的分页方法，传入查询条件和分页参数，返回分页结果
        return this.page(page, queryWrapper);
    }
}
